﻿using System;
using System.Collections.Generic;
using System.Linq;
using TeamLemonApp.Models;

namespace TeamLemonApp.DataPersisters
{
    public class RecipeDataPersister
    {
        private const string BaseServicesUrl = "http://arialwebapirecipe.apphb.com/api/";

        public static void AddRecipe(string sessionKey, RecipeDetail recipe)
        {
            HttpRequester.Post(BaseServicesUrl + "recipes/add/" + sessionKey, recipe);
        }

        public static IEnumerable<RecipeInfo> GetRecipesForPage(int pageNumber)
        {
            ICollection<RecipeInfo> recipes = HttpRequester.Get<ICollection<RecipeInfo>>(BaseServicesUrl + "recipes/page/" + pageNumber);

            return recipes;
        }

        public static RecipeDetail GetRecipeById(int id)
        {
            RecipeDetail recipe = HttpRequester.Get<RecipeDetail>(BaseServicesUrl + "recipes/recipe/" + id);

            return recipe;
        }

        public static ICollection<PreparationStepInfo> GetStepsForRecipe(int id)
        {
            ICollection<PreparationStepInfo> steps = HttpRequester.Get<ICollection<PreparationStepInfo>>(
                BaseServicesUrl + "recipes/steps/" + id);

            return steps;
        }

        public static IEnumerable<RecipeInfo> GetRecipesByContainingText(string containingText)
        {
            IEnumerable<RecipeInfo> recipes = HttpRequester.Get<IEnumerable<RecipeInfo>>(
                          BaseServicesUrl + "recipes/search/" + containingText);

            return recipes;
        }

        public static void StartCooking(int recipeId, string sessionKey)
        {
            HttpRequester.Get(BaseServicesUrl + "api/recipes/recipe/" + recipeId + "/start/" + sessionKey);
        }
    }
}
